home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_m_p / pcpwhost.zip / HOST1A.COM / MAIL.WAS < prev    next >
Text File  |  1992-06-18  |  20KB  |  613 lines

  1. ; Host Mode Mail v1.00a include file - Do not compile!
  2.  
  3. ;***********************************************************************
  4. ;*                                                                     *   
  5. ;* MAIL.WAS                                                            *
  6. ;* Copyright (C) 1992 Datastorm Technologies, Inc.                     *     
  7. ;* All rights reserverd.                                               * 
  8. ;*                                                                     * 
  9. ;* Purpose: Contains the Host Mail routines for Host Mode              *
  10. ;*                                                                     * 
  11. ;***********************************************************************
  12.  
  13. ;***********************************************************************
  14. ;*                                                                     *
  15. ;*  WARNING!!!!                                                        *
  16. ;*                                                                     *
  17. ;*  Do not modify this script file unless you have a good under-       *
  18. ;*  standing of the Windows ASPECT language.  If you do modify this    *
  19. ;*  script, PLEASE MAKE A BACKUP before doing so.                      *
  20. ;*                                                                     *
  21. ;***********************************************************************
  22.  
  23. ;***********************************************************************
  24. ;*                                                                     *
  25. ;* Structure of HOST.HDR for each message in the HOST.MSG file         *
  26. ;*                                                                     *
  27. ;* integer   2 bytes message number                                    *
  28. ;* long      4 bytes offset            - offset into the HOST.MSG file *
  29. ;* integer   2 bytes message length    - length of message in HOST.MSG *
  30. ;* char      1 bytes flag              - see below                     *
  31. ;* string   31 bytes destination       - TO:                           *
  32. ;* string   31 bytes from              - FROM:                         *
  33. ;* string   37 bytes subject           - SUBJECT:                      *
  34. ;* string    9 bytes date              - date message was created      *
  35. ;* string   11 bytes time              - time message was created      *
  36. ;*                                                                     *
  37. ;*  The mail flag is set by adding the desired attributes together.    *
  38. ;*       PUBLIC     0         - anyone can read                        *
  39. ;*       PRIVATE    1         - only TO: and FROM: can read or delete  *
  40. ;*       NEWMAIL    2         - hasn't been read                       *
  41. ;*       DELETED    4         - marked for deletion                    *
  42. ;*                                                                     *
  43. ;* All strings include a NULL at the last position.                    *
  44. ;*                                                                     *
  45. ;***********************************************************************
  46.  
  47. ;***********************************************************************
  48. ;*                                                                     *   
  49. ;* LEAVEMAIL                                                           *
  50. ;*                                                                     *
  51. ;* This procedure creates the mail messages                            *
  52. ;*                                                                     *
  53. ;*                                                                     * 
  54. ;* Calls: HOSTPUTS, HOSTGETS, HOSTGETYN, HOSTGETC, SETFAILURE,         *
  55. ;*        HOSTMSGBOX,   EXITHOST,     MAILGETLINE,  COUNTMSG           *
  56. ;*                                                                     *
  57. ;* Modifies globals: tempfile, name, msgfile, hdrfile                  *
  58. ;*                                                                     *
  59. ;* Labels : GETMESSAGE, LOOP                                           *
  60. ;*                                                                     *
  61. ;***********************************************************************
  62. proc LeaveMail
  63. intparm replyflag
  64. strparm subject
  65. strparm destination
  66. string line, line_num, choice
  67. integer mailflag, line_count, msg_num, chars_to_read, blocksize
  68. integer dummy, length, count
  69. long msgfile_offset, msg_length
  70.  
  71.    fetch aspect scriptpath tempfile
  72.    addfilename tempfile "~HOST.TMP"
  73.    if isfile tempfile
  74.       delfile tempfile
  75.    endif
  76.     
  77.    while 1
  78.       line_count=1
  79.       if ! replyflag
  80.          HostPutS("`r`n`r`n  To: ")
  81.          HostGetS(&destination 30 DISP)
  82.          strupr destination
  83.       endif
  84.  
  85.       if ! replyflag
  86.          HostPutS("`r`nSubj: ")
  87.          HostGetS(&subject 40 DISP)
  88.       endif
  89.  
  90.       HostPutS("`r`n`r`n")
  91.         
  92.       HostPutS("Private Mail (Y/N)? ")
  93.       HostGetYN()
  94.       if success
  95.          mailflag=PRIVATE+NEWMAIL
  96.       else
  97.          mailflag=PUBLIC+NEWMAIL
  98.       endif
  99.         
  100.       HostPutS("`r`n`r`n  To: ")
  101.       HostPutS(destination)
  102.       HostPuts("`r`nFrom: ")
  103.       HostPutS(name)
  104.       HostPutS("`r`nSubj: ")
  105.       HostPutS(subject)
  106.       if ! replyflag
  107.          HostPutS("`r`n`r`nIs this correct (Y/N/Q)? ")
  108.          HostGetC(&choice)
  109.          if not success
  110.             SetFailure()
  111.             return
  112.          endif
  113.          HostPutS(choice)
  114.          HostPutS("`r`n")
  115.          strupr choice
  116.          switch choice
  117.             case "Y"
  118.             endcase
  119.             case "N"
  120.                loopwhile
  121.             endcase
  122.             case "Q"
  123.                return
  124.             endcase
  125.          endswitch
  126.       endif
  127.       fopen 1 tempfile CREATE
  128.       if not success
  129.          HostMsgBox("FATAL ERROR - Can't open TEMP file!")
  130.          ExitHost()
  131.       endif
  132.  
  133. GETMESSAGE:
  134.       while 1
  135.          strfmt line_num "%5d: " line_count
  136.          HostPutS("`r`n")
  137.          HostPutS(line_num)
  138.          MailGetLine(&line)
  139.          strcmp line ""
  140.          if success
  141.             exitwhile
  142.          endif
  143.          fputs 1 line        ; write line to tempfile
  144.          fputc 1 0x0D        ; append CR to line
  145.          fputc 1 0x0A        ; append LF to line
  146.          line_count++
  147.       endwhile
  148.  
  149. LOOP:
  150.       HostPutS("`r`n`r`nS)ave A)bort D)isplay C)ontinue ? ")
  151.       HostGetC(&choice)
  152.       strupr choice
  153.       HostPutS(choice)
  154.       if success
  155.          HostPutS("`r`n")
  156.          strupr choice
  157.          switch choice
  158.             case "S"
  159.                HostPuts("`r`nSaving message ...`r`n")
  160.                isfile msgfile
  161.                if success
  162.                   fopen 0 msgfile WRITE
  163.                   if not success
  164.                      HostMsgBox("FATAL ERROR - Can't open HOST.MSG file!")
  165.                      halt
  166.                   endif
  167.                else
  168.                   fopen 0 msgfile CREATE
  169.                endif
  170.                fseek 0 0 2
  171.                ftell 0 msgfile_offset
  172.                         
  173.                fclose 1
  174.                findfirst tempfile
  175.                msg_length=$FSIZE
  176.                fopen 1 tempfile READWRITE
  177.                length=msg_length
  178.                chars_to_read = msg_length
  179.  
  180.                fseek 0 0 2
  181.                while chars_to_read > 0
  182.                   if chars_to_read > 128
  183.                      blocksize = 128
  184.                   else
  185.                      blocksize = chars_to_read
  186.                   endif
  187.  
  188.                   fread 1 line blocksize dummy
  189.                   fwrite 0 line blocksize
  190.                   if not success
  191.                      HostMsgBox("FATAL ERROR - Can't write to HOST.MSG file!")
  192.                      halt
  193.                   endif
  194.                   chars_to_read = chars_to_read - blocksize
  195.                endwhile
  196.                fclose 0
  197.                fclose 1
  198.                delfile tempfile
  199.                     
  200.                ;count messages to get this message number
  201.                CountMsg(&msg_num)
  202.  
  203.                ;write header info
  204.                isfile hdrfile
  205.                if success
  206.                   fopen 2 hdrfile WRITE
  207.                   if not success
  208.                      HostMsgBox("FATAL ERROR - Can't open HOST.MSG file!")
  209.                      halt
  210.                   endif
  211.                else
  212.                   fopen 2 hdrfile create
  213.                endif
  214.  
  215.                fseek 2 0 2
  216.                CountMsg(&msg_num)
  217.                inc msg_num
  218.                fputi 2 msg_num
  219.                fputl 2 msgfile_offset
  220.                fputi 2 length
  221.                fputc 2 mailflag
  222.                fwrite 2 destination 31
  223.                fwrite 2 name 31
  224.                fwrite 2 subject 37
  225.                fwrite 2 $DATE 9
  226.                fwrite 2 $TIME 11
  227.                fclose 2
  228.             endcase
  229.                 
  230.             case "A"
  231.                HostPutS("`r`nAbort message (Y/N)? ")
  232.                HostGetYN()
  233.                if success
  234.                   fclose 1
  235.                   delfile tempfile
  236.                   return
  237.                endif
  238.                HostPutS("`r`n")
  239.                goto LOOP
  240.             endcase
  241.                 
  242.             case "D"
  243.                count=1
  244.                rewind 1
  245.                while 1
  246.                   fgets 1 line
  247.                   if FEOF 1
  248.                      exitwhile
  249.                   endif
  250.                   HostPutS(line)
  251.                   inc count
  252.                   if count==23
  253.                      count=1
  254.                      HostPuts("-MORE-")
  255.                      HostGetC(&choice)
  256.                      HostPutS("`b`b`b`b`b`b")
  257.                      strupr choice
  258.                      strcmp choice "N"
  259.                      if success
  260.                            exitwhile
  261.                      endif
  262.                   endif
  263.                endwhile
  264.                goto LOOP
  265.             endcase
  266.                 
  267.             case "C"
  268.                goto GETMESSAGE
  269.             endcase
  270.          
  271.             default
  272.                goto LOOP
  273.             endcase
  274.          endswitch
  275.       else
  276.          SetFailure()
  277.       endif
  278.       return
  279.    endwhile
  280. endproc
  281.  
  282. ;***********************************************************************
  283. ;*                                                                     *   
  284. ;* READMAIL                                                            *
  285. ;*                                                                     *
  286. ;* This procedure reads and displays mail messages                     *
  287. ;*                                                                     * 
  288. ;* Calls: COUNTMSG, HOSTPUTS, HOSTGETC, SETFAILURE, HOSTGETS, READMSG  *
  289. ;*                                                                     *
  290. ;* Modifies globals: msg, msg_number                                   *
  291. ;*                                                                     *
  292. ;* Labels : LOOP                                                       *
  293. ;*                                                                     *
  294. ;***********************************************************************
  295. proc ReadMail
  296. string choice
  297. integer msg_total,  searchflag
  298.  
  299. LOOP:
  300.    CountMsg(&msg_total)
  301.    strfmt msg "`r`n`r`nTotal messages: %d`r`n`r`n" msg_total
  302.    HostPutS(msg)
  303.    HostPutS("F)orward read`r`n")
  304.    HostPutS("N)ew mail`r`n")
  305.    HostPutS("S)earch mail`r`n")
  306.    HostPutS("Q)uit`r`n`r`n? ")
  307.    HostGetC(&choice)
  308.    if not success
  309.       SetFailure()
  310.       return
  311.    endif
  312.    HostPuts(choice)
  313.    HostPuts("`r`n")
  314.    strupr choice
  315.    switch choice
  316.       case "F"
  317.          HostPuts("`r`nStarting message number (<CR> for first): ")
  318.          HostGetS(&choice 5 DISP)
  319.          if not success
  320.             SetFailure()
  321.             return
  322.          endif
  323.          HostPuts("`r`n")
  324.          strcmp choice ""
  325.          if success
  326.             msg_number=1
  327.          else
  328.             atoi choice msg_number
  329.             if msg_number>msg_total
  330.                HostPutS("`r`nInvalid msg number!`r`n")
  331.                goto LOOP
  332.             endif
  333.          endif
  334.          while msg_number<=msg_total
  335.             ReadMsg(0)
  336.             if not success
  337.                exitwhile
  338.             endif
  339.          endwhile
  340.          HostPutS("`r`nEnd of messages.`r`n")
  341.          goto LOOP
  342.       endcase
  343.  
  344.       case "N"
  345.          msg_number=1
  346.          while msg_number<=msg_total
  347.             ReadMsg(1)
  348.             if not success
  349.                exitwhile
  350.             endif
  351.          endwhile
  352.          HostPutS("`r`nEnd of messages.`r`n")
  353.          goto LOOP
  354.       endcase
  355.  
  356.       case "S"
  357.          HostPutS("`r`n`r`nWhich field:  T)o  F)rom  or  S)ubject ? ")
  358.          HostGetS(&choice 1 DISP)
  359.          if not success
  360.             SetFailure()
  361.             return
  362.          endif
  363.          HostPuts("`r`n")
  364.          strupr choice
  365.          switch choice
  366.             case "T"
  367.                searchflag=2
  368.             endcase
  369.             case "F"
  370.                searchflag=3
  371.             endcase
  372.             case "S"
  373.                searchflag=4
  374.             endcase
  375.  
  376.             default
  377.                return
  378.             endcase
  379.          endswitch
  380.          HostPuts("Search string: ")
  381.          HostGetS(&searchstr 30 DISP)
  382.          HostPutS("`r`n")
  383.          if not success
  384.             SetFailure()
  385.             return
  386.          endif
  387.          msg_number=1
  388.          while msg_number<=msg_total
  389.             ReadMsg(searchflag)
  390.             if not success
  391.                exitwhile
  392.             endif
  393.          endwhile
  394.          HostPutS("`r`nEnd of messages.`r`n")
  395.          goto LOOP
  396.  
  397.       endcase
  398.  
  399.       case "Q"
  400.          return
  401.       endcase
  402.  
  403.       default
  404.          goto LOOP
  405.       endcase
  406.    endswitch
  407. endproc
  408.  
  409. ;***********************************************************************
  410. ;*                                                                     *   
  411. ;* READMSG                                                             *
  412. ;*                                                                     *
  413. ;* This procedure opens and displays a mail message.                   *
  414. ;*                                                                     *
  415. ;* Calls: HOSTPUTS, HOSTMSGBOX, EXITHOST, CHANGEFLAG, DISPLAYFILE,     *
  416. ;*        HOSTGETC, SETFAILURE, LEAVEMAIL, DELETEMSG                   *
  417. ;*                                                                     *
  418. ;* Modifies globals: tempfile, hdrfile, msg_number, _date, _time,      *
  419. ;*                   access_level, name, msg, msgfile                  *
  420. ;*                                                                     *
  421. ;* Labels: LOOP                                                        *
  422. ;*                                                                     *
  423. ;***********************************************************************
  424. proc ReadMsg
  425. intparm readflag
  426. integer msg_num, msg_length, msg_flag, dummy, chars_to_read, blocksize
  427. long offset, hdr_offset
  428. string destination, from, subject,flag, line, choice, reply="REPLY - "
  429.  
  430.    fetch aspect scriptpath tempfile
  431.    addfilename tempfile "~HOST.TMP"
  432.  
  433.    isfile hdrfile
  434.    if not success
  435.       HostPutS("`r`nNo mail file found!`r`n")
  436.       return
  437.    endif
  438.  
  439.    fopen 0 hdrfile READWRITE
  440.    if not success
  441.       HostMsgBox("FATAL ERROR - Can't open HOST.HDR!")
  442.       ExitHost()
  443.    endif
  444.  
  445.    hdr_offset=(msg_number-1)*128       ; goto a specific record in .HDR file
  446.    fseek 0 hdr_offset 0
  447. LOOP:
  448.  
  449.    fgeti 0 msg_num
  450.    if FEOF 0
  451.       SetFailure()
  452.       inc msg_number
  453.       return
  454.    endif
  455.    fgetl 0 offset
  456.    fgeti 0 msg_length
  457.    fgetc 0 msg_flag
  458.    if (msg_flag & 1) ==1
  459.       flag="Private"              ;remove new mail flag
  460.    else
  461.       flag="Public"
  462.    endif
  463.    fread 0 destination 31 dummy
  464.    fread 0 from 31 dummy
  465.    fread 0 subject 37 dummy
  466.    fread 0 _date 9 dummy
  467.    fread 0 _time 11 dummy
  468.  
  469.    if (msg_flag & 1)==1                      ; if message is PRIVATE
  470.       strcmp access_level "2"
  471.       if not success
  472.          strcmp name destination         ; compare user name to TO:
  473.          if not success
  474.             strcmp name from            ; compare user name to FROM:
  475.             if not success
  476.                inc msg_number
  477.                goto LOOP
  478.             endif
  479.          endif
  480.       endif
  481.    endif
  482.  
  483.    if (msg_flag & 4)==DELETED
  484.       inc msg_number
  485.       goto LOOP
  486.    endif
  487.  
  488.    switch readflag
  489.       case 1        ; read new mail only
  490.          strcmp destination name
  491.          if not success
  492.             inc msg_number
  493.             goto loop
  494.          endif
  495.          if (msg_flag & 2)!=NEWMAIL
  496.             inc msg_number
  497.             goto LOOP
  498.          endif
  499.       endcase
  500.  
  501.       case 2         ; search for TO:
  502.          if not strfind destination searchstr
  503.             inc msg_number
  504.             goto LOOP
  505.          endif
  506.       endcase
  507.  
  508.       case 3         ; search for FROM:
  509.          if not strfind from searchstr
  510.             inc msg_number
  511.             goto LOOP
  512.          endif
  513.       endcase
  514.  
  515.       case 4         ; search for SUBJECT
  516.          if not strfind subject searchstr
  517.             inc msg_number
  518.             goto LOOP
  519.          endif
  520.       endcase
  521.  
  522.    endswitch
  523.    fclose 0
  524.  
  525.    strcmp destination name
  526.    if success
  527.       msg_flag=msg_flag & 1               ;unset NEWMAIL flag
  528.       ChangeFlag(msg_flag)
  529.    endif
  530.  
  531.    strfmt msg "`r`n Msg: %d  (%s, sent %s at %s)`r`n" msg_num flag _date _time
  532.    HostPutS(msg)
  533.    strfmt msg "From: %s`r`n" from
  534.    HostPuts(msg)
  535.    strfmt msg "  To: %s`r`n" destination
  536.    HostPutS(msg)
  537.    strfmt msg "Subj: %s`r`n`r`n" subject
  538.    HostPutS(msg)
  539.  
  540.    isfile msgfile
  541.    if not success
  542.       HostMsgBox("No message file!")
  543.       return
  544.    else
  545.       fopen 1 msgfile READ text
  546.       if not success
  547.          HostMsgBox("Can't open message file!")
  548.          return
  549.       endif
  550.       fopen 2 tempfile create text
  551.       if not success
  552.          HostMsgBox("Can't open temp file!")
  553.          return
  554.       endif
  555.  
  556.       fseek 1 offset 1
  557.  
  558.       chars_to_read = msg_length
  559.       while chars_to_read > 0
  560.          if chars_to_read > 128
  561.             blocksize = 128
  562.          else
  563.             blockSize = chars_to_read
  564.          endif
  565.          fread 1 line blocksize dummy
  566.          fwrite 2 line blocksize
  567.          if not success
  568.             HostMsgBox("Can't write to temp file!")
  569.             halt
  570.          endif
  571.          chars_to_read = chars_to_read - blocksize
  572.       endwhile
  573.  
  574.       fclose 1
  575.       fclose 2
  576.       DisplayFile(tempfile, 17)
  577.       delfile tempfile
  578.         
  579.       HostPutS("`r`nR)eply  D)elete  Q)uit  (<CR> for another): ")
  580.       HostGetC(&choice)
  581.       if not success
  582.          SetFailure()
  583.          return
  584.       endif
  585.       HostPutS(choice)
  586.       HostPutS("`r`n")
  587.       switch choice
  588.          case "R"
  589.             substr msg subject 0 21
  590.             strcat reply msg
  591.             LeaveMail(1, reply, from)
  592.             inc msg_number
  593.             return
  594.          endcase
  595.          case "D"
  596.             DeleteMsg()
  597.          endcase
  598.          case "Q"
  599.             SetFailure()
  600.             return
  601.          endcase
  602.          case "`r"
  603.             inc msg_number
  604.             return
  605.          endcase
  606.          default
  607.             choice=""
  608.          endcase
  609.       endswitch
  610.    endif
  611. endproc
  612. ;**** End of MAIL.WAS ****
  613.